Public Class sqlClient
    Structure computerDetails
        Dim guid As String
        Dim name As String
        Dim ip As String
        Dim groupID As Integer
        Dim overallStatus As String
        Dim make As String
        Dim model As String
        Dim thermalState As Integer
        Dim arch As String
        Dim cpuCount As Integer
        Dim loggedInUser As String
        Dim serialNumber As String
        Dim osName As String
        Dim osVersion As String
        Dim freeRAM As Integer
        Dim totalRAM As Integer
        Dim uptime As String
        Dim localDrivesLetters() As String
        Dim localDrivesPercentFree() As String
        Dim localDrivesFreeSpace() As String
        Dim cpuName() As String
        Dim cpuSpeed() As String
        Dim processCount As Integer
        Dim threadCount As Integer
        Dim rebootFlag As Long
        Dim clientVersion As String
        Dim sessionStatus As String
    End Structure

    Enum eventLogType
        'all informational types here
        i__Informational = 100
        i_ServerState = 101
        i_NewClient = 110

        'all warning types here
        ii__Warnings = 500

        'all error types here
        iii__Errors = 800

        'all unknow types here - but come on now, how don't you know?!
        iv__Unknown = 1000
    End Enum

    Enum eventLogComponets
        'server parts
        server = 10
        serverController = 11
        serverListener = 12
        serverClientThread = 13
    End Enum

    Public Function connect() As System.Data.SqlClient.SqlConnection
        Dim DB As New System.Data.SqlClient.SqlConnection
        Dim connectStr As String = "Initial Catalog=" & dbName & ";data source=" & dbServerName & ";min pool size=3;max pool size=50;user id= " & dbUserName & "; password="

        log.write("Attempting to connect to database using connect string: " & connectStr)
        DB.ConnectionString = connectStr & dbPassword & ";"
        DB.Open()

        If DB.State = ConnectionState.Open Then
            log.write("Connected successfully!")
        Else
            log.write("Connection state: " & DB.State)
        End If

        Return DB
    End Function

    Sub disconnect(ByRef db As System.Data.SqlClient.SqlConnection)
        log.write("Attempting to disconnect from database...")
        DB.Close()
        log.write("Disconnected from database!")
    End Sub

    Public Sub addToEventLog(ByVal type As eventLogType, ByVal component As eventLogComponets, ByVal msg As String)
        Dim cmdWriter As System.Data.SqlClient.SqlCommand
        Dim sql As String
        Dim DB As System.Data.SqlClient.SqlConnection = connect()

        sql = "insert into event_log(type, component, message) values"
        sql = sql & " (" & type & ", " & component & ", '" & msg & "')"
        log.write("Writing the following to the event log: " & sql)
        cmdWriter = New System.Data.SqlClient.SqlCommand(sql, DB)
        cmdWriter.ExecuteNonQuery()
        log.write("Wrote to eventlog successful!")
        disconnect(db)
    End Sub

    Public Function newClient(ByVal guid As String) As Boolean
        Dim DB As System.Data.SqlClient.SqlConnection = connect()
        Dim cmd As New System.Data.SqlClient.SqlCommand

        If guid = "0" Then
            Return True
        Else
            cmd.Connection = DB
            cmd.CommandText = "select count(*) from clients where id = '" & guid & "'"
            If cmd.ExecuteScalar > 0 Then Return False Else Return True
        End If
    End Function

    Public Function getClientInformation(ByVal guid As String) As computerDetails
        Dim cmd As System.Data.SqlClient.SqlCommand
        Dim sqlData As System.Data.SqlClient.SqlDataReader
        Dim sql As String
        Dim myReturn As computerDetails
        Dim DB As System.Data.SqlClient.SqlConnection = connect()

        sql = "select * from clients where id = '" & guid & "'"
        cmd = New Data.SqlClient.SqlCommand(sql, DB)
        sqlData = cmd.ExecuteReader

        'If Not sqlData.HasRows Then
        'sqlData.Close()
        'sql = "select * from clients where old_computer_name = '" & name & "'"
        'cmd = New Data.SqlClient.SqlCommand(sql, DB)
        'sqlData = cmd.ExecuteReader

        'If Not sqlData.HasRows Then
        'sqlData.Close()
        'sql = "select * from clients where computer_name = '" & name & "'"
        'cmd = New Data.SqlClient.SqlCommand(sql, DB)
        'sqlData = cmd.ExecuteReader
        'End If
        'End If

        If sqlData.Read() Then
            With myReturn
                .name = sqlData.Item("computer_name")
                .ip = sqlData.Item("last_ip")
                .groupID = sqlData.Item("group_id")
                .overallStatus = sqlData.Item("overall_status")
                .make = sqlData.Item("machine_make")
                .model = sqlData.Item("machine_model")
                .thermalState = sqlData.Item("thermal_state")
                .arch = sqlData.Item("system_arch")
                .cpuCount = sqlData.Item("cpu_count")
                .loggedInUser = sqlData.Item("loggedin_user")
                .serialNumber = sqlData.Item("serial_number")
                .osName = sqlData.Item("os_name")
                .osVersion = sqlData.Item("os_version")
                .freeRAM = sqlData.Item("free_ram")
                .totalRAM = sqlData.Item("total_ram")
                .uptime = sqlData.Item("uptime")
                .localDrivesLetters = Split(sqlData.Item("local_drive_letters"), ":")
                .localDrivesPercentFree = Split(sqlData.Item("local_drive_percent_free"), ":")
                .localDrivesFreeSpace = Split(sqlData.Item("local_drive_free_space"), ":")
                .cpuName = Split(sqlData.Item("cpu_title"), ":")
                .cpuSpeed = Split(sqlData.Item("cpu_speed"), ":")
                .processCount = sqlData.Item("process_count")
                .threadCount = sqlData.Item("thread_count")
                .guid = sqlData.Item("id").ToString
                .rebootFlag = sqlData.Item("reboot_flag")
                .clientVersion = sqlData.Item("client_version")
                .sessionStatus = sqlData.Item("session_status")
            End With
        Else
            With myReturn
                .groupID = -1
                .guid = guid
            End With
        End If
        sqlData.Close()

        disconnect(DB)
        Return myReturn
    End Function

    Public Function addClient(ByVal name As String, ByVal ip As String, ByVal data As String) As String
        Dim cmd As Data.SqlClient.SqlCommand
        Dim sql As String
        Dim info() As String
        Dim guid As String
        Dim DB As System.Data.SqlClient.SqlConnection = connect()

        sql = "insert into clients(computer_name, last_ip, last_checkin, group_id) values('" & name & "', '" & ip & "', getdate(), 0)"
        cmd = New Data.SqlClient.SqlCommand(sql, DB)
        cmd.ExecuteNonQuery()

        cmd.CommandText = "select @@IDENTITY from clients"
        guid = cmd.ExecuteScalar
        cmd.CommandText = "select id from clients where rowid = " & guid.ToString
        guid = cmd.ExecuteScalar.ToString

        info = Split(data, "::")
        sql = "update clients set last_ip = '" & ip & "'"
        sql = sql & ", last_checkin = getdate()"
        sql = sql & ", overall_status = '" & info(1) & "'"
        sql = sql & ", machine_make = '" & info(2) & "'"
        sql = sql & ", machine_model = '" & info(3) & "'"
        sql = sql & ", thermal_state = '" & info(4) & "'"
        sql = sql & ", system_arch = '" & info(5) & "'"
        sql = sql & ", cpu_count = '" & info(6) & "'"
        sql = sql & ", loggedin_user = '" & info(7) & "'"
        sql = sql & ", serial_number = '" & info(8) & "'"
        sql = sql & ", os_name = '" & info(9) & "'"
        sql = sql & ", os_version = '" & info(12) & "'"
        sql = sql & ", free_ram = '" & info(10) & "'"
        sql = sql & ", total_ram = '" & info(11) & "'"
        sql = sql & ", uptime = '" & info(13) & "'"
        sql = sql & ", local_drive_letters = '" & info(14) & "'"
        sql = sql & ", local_drive_percent_free = '" & info(15) & "'"
        sql = sql & ", local_drive_free_space = '" & info(16) & "'"
        sql = sql & ", cpu_title = '" & info(17) & "'"
        sql = sql & ", cpu_speed = '" & info(18) & "'"
        sql = sql & ", process_count = '" & info(19) & "'"
        sql = sql & ", thread_count = '" & info(20) & "'"
        sql = sql & ", client_version = '" & info(23) & "'"
        sql = sql & ", session_status = '" & info(24) & "'"
        sql = sql & " where id = '" & guid & "'"
        cmd.CommandText = sql
        cmd.ExecuteNonQuery()

        disconnect(DB)
        Return guid
    End Function

    Public Sub clientCheckIn(ByVal guid As String, ByVal name As String, ByVal ip As String, ByVal data As String)
        Dim cmd As Data.SqlClient.SqlCommand
        Dim sql As String
        Dim info() As String
        Dim DB As System.Data.SqlClient.SqlConnection = connect()

        info = Split(data, "::")
        sql = "update clients set last_ip = '" & ip & "'"
        sql = sql & ", computer_name = '" & name & "'"
        sql = sql & ", last_checkin = getdate()"
        sql = sql & ", overall_status = '" & info(1) & "'"
        sql = sql & ", machine_make = '" & info(2) & "'"
        sql = sql & ", machine_model = '" & info(3) & "'"
        sql = sql & ", thermal_state = '" & info(4) & "'"
        sql = sql & ", system_arch = '" & info(5) & "'"
        sql = sql & ", cpu_count = '" & info(6) & "'"
        sql = sql & ", loggedin_user = '" & info(7) & "'"
        sql = sql & ", serial_number = '" & info(8) & "'"
        sql = sql & ", os_name = '" & info(9) & "'"
        sql = sql & ", os_version = '" & info(12) & "'"
        sql = sql & ", free_ram = '" & info(10) & "'"
        sql = sql & ", total_ram = '" & info(11) & "'"
        sql = sql & ", uptime = '" & info(13) & "'"
        sql = sql & ", local_drive_letters = '" & info(14) & "'"
        sql = sql & ", local_drive_percent_free = '" & info(15) & "'"
        sql = sql & ", local_drive_free_space = '" & info(16) & "'"
        sql = sql & ", cpu_title = '" & info(17) & "'"
        sql = sql & ", cpu_speed = '" & info(18) & "'"
        sql = sql & ", process_count = '" & info(19) & "'"
        sql = sql & ", thread_count = '" & info(20) & "'"
        sql = sql & ", client_version = '" & info(23) & "'"
        sql = sql & ", session_status = '" & info(24) & "'"
        sql = sql & " where id = '" & guid & "'"
        cmd = New Data.SqlClient.SqlCommand(sql, DB)
        cmd.ExecuteNonQuery()
        disconnect(DB)

    End Sub

    Public Function getPolicyDetails(ByVal group As Integer) As Object
        Dim myReturn As policyType
        Dim cmd As System.Data.SqlClient.SqlCommand
        Dim sqlData As System.Data.SqlClient.SqlDataReader
        Dim sql As String
        Dim tempValues(50) As Object
        Dim DB As System.Data.SqlClient.SqlConnection = connect()

        If group = 0 Then
            sql = "select * from policies where id = 0"
        Else
            sql = "select p.* from policies p, groups g where g.id = " & group & " and g.policy_id = p.id"
        End If
        cmd = New Data.SqlClient.SqlCommand(sql, DB)
        sqlData = cmd.ExecuteReader

        myReturn.name = ""
        myReturn.checkInTime = -1
        If sqlData.Read Then
            myReturn.id = sqlData.Item("id")
            myReturn.name = sqlData.Item("name")
            myReturn.checkInTime = sqlData.Item("checkin_time")
            If sqlData.Item("reboot_reminder_1") Is DBNull.Value Then
                myReturn.rebootPolicy.time1 = ern_defaultRebootReminderTime1
                myReturn.rebootPolicy.useTime1 = False
            Else
                myReturn.rebootPolicy.time1 = sqlData.Item("reboot_reminder_1")
                myReturn.rebootPolicy.useTime1 = True
            End If
            If sqlData.Item("reboot_reminder_2") Is DBNull.Value Then
                myReturn.rebootPolicy.time2 = ern_defaultRebootReminderTime2
                myReturn.rebootPolicy.useTime2 = False
            Else
                myReturn.rebootPolicy.time2 = sqlData.Item("reboot_reminder_2")
                myReturn.rebootPolicy.useTime2 = True
            End If
            If sqlData.Item("reboot_reminder_3") Is DBNull.Value Then
                myReturn.rebootPolicy.time3 = ern_defaultRebootReminderTime3
                myReturn.rebootPolicy.useTime3 = False
            Else
                myReturn.rebootPolicy.time3 = sqlData.Item("reboot_reminder_3")
                myReturn.rebootPolicy.useTime3 = True
            End If
            myReturn.rebootPolicy.everyFewMinutes = sqlData.Item("reboot_reminder_interval")
            myReturn.rebootPolicy.rebootSchedule = sqlData.Item("reboot_reminder_schedule")
            myReturn.rebootPolicy.scheduledRebootDay = sqlData.Item("reboot_reminder_scheduled_day")
            myReturn.auPolicy.enabled = sqlData.Item("au_enabled")
            myReturn.auPolicy.day = sqlData.Item("au_day")
            myReturn.auPolicy.time = sqlData.Item("au_time")
        Else
            If group = 0 Then myReturn.id = 0 Else myReturn.id = -1
            myReturn.checkInTime = ern_defaultCheckInTime
            myReturn.name = "__DEFAULT__"
            myReturn.rebootPolicy.time1 = ern_defaultRebootReminderTime1
            myReturn.rebootPolicy.useTime1 = True
            myReturn.rebootPolicy.time2 = ern_defaultRebootReminderTime2
            myReturn.rebootPolicy.useTime2 = True
            myReturn.rebootPolicy.time3 = ern_defaultRebootReminderTime3
            myReturn.rebootPolicy.useTime3 = True
            myReturn.rebootPolicy.everyFewMinutes = ern_defaultRebootReminderInterval
            myReturn.rebootPolicy.rebootSchedule = ern_defaultRebootReminderSchedule
            myReturn.rebootPolicy.scheduledRebootDay = ern_defaultScheduledRebootDay
            myReturn.auPolicy.enabled = ern_defaultAUEnabled
            myReturn.auPolicy.day = ern_defaultAUDay
            myReturn.auPolicy.time = ern_defaultAUTime
        End If
        sqlData.Close()

        disconnect(DB)
        Return myReturn
    End Function

    Public Sub setPolicyDetails(ByRef policy As policyType)
        Dim cmd As System.Data.SqlClient.SqlCommand
        Dim sqlData As System.Data.SqlClient.SqlDataReader
        Dim sql As String
        Dim tempValues(50) As Object
        Dim DB As System.Data.SqlClient.SqlConnection = connect()
        Dim translatePolicy As Integer = 0

        If policy.auPolicy.enabled Then translatePolicy = 1
        sql = "select * from policies where id = " & policy.id
        cmd = New Data.SqlClient.SqlCommand(sql, DB)
        sqlData = cmd.ExecuteReader

        If sqlData.HasRows Then
            sql = "update policies set "
            sql = sql & " name = '" & policy.name & "'"
            sql = sql & ", checkin_time = '" & policy.checkInTime & "'"
            If policy.rebootPolicy.useTime1 Then
                sql = sql & ", reboot_reminder_1 = '" & policy.rebootPolicy.time1 & "'"
            Else
                sql = sql & ", reboot_reminder_1 = null"
            End If
            If policy.rebootPolicy.useTime2 Then
                sql = sql & ", reboot_reminder_2 = '" & policy.rebootPolicy.time2 & "'"
            Else
                sql = sql & ", reboot_reminder_2 = null"
            End If
            If policy.rebootPolicy.useTime3 Then
                sql = sql & ", reboot_reminder_3 = '" & policy.rebootPolicy.time3 & "'"
            Else
                sql = sql & ", reboot_reminder_3 = null"
            End If
            sql = sql & ", reboot_reminder_interval = " & policy.rebootPolicy.everyFewMinutes
            sql = sql & ", reboot_reminder_schedule = " & policy.rebootPolicy.rebootSchedule
            sql = sql & ", reboot_reminder_scheduled_day = " & policy.rebootPolicy.scheduledRebootDay
            sql = sql & ", au_enabled = " & translatePolicy
            sql = sql & ", au_day = " & policy.auPolicy.day
            sql = sql & ", au_time = '" & policy.auPolicy.time & "'"
            sql = sql & " where id = " & policy.id
            sqlData.Close()
            cmd.CommandText = sql
            cmd.ExecuteNonQuery()
        Else
            Dim r As New Random(Now.Millisecond)

            If policy.id = 0 Then
                sql = "insert into policies(id, name, checkin_time, reboot_reminder_1, reboot_reminder_2, reboot_reminder_3, reboot_reminder_interval, reboot_reminder_schedule, reboot_reminder_scheduled_day, au_enabled, au_day, au_time) "
                sql = sql & " values(0,"
                sql = sql & "'policy_" & r.Next(1, 7052007) & "', " & policy.checkInTime & ", '" & policy.rebootPolicy.time1 & "', '" & policy.rebootPolicy.time2 & "', '" & policy.rebootPolicy.time3 & "', " & policy.rebootPolicy.everyFewMinutes & ", " & policy.rebootPolicy.rebootSchedule & ", " & policy.rebootPolicy.scheduledRebootDay & ", " & translatePolicy & ", " & policy.auPolicy.day & ", '" & policy.auPolicy.time & "'"
                sql = sql & ")"
                sqlData.Close()
                cmd.CommandText = "set IDENTITY_INSERT policies ON"
                cmd.ExecuteNonQuery()
                cmd.CommandText = sql
                cmd.ExecuteNonQuery()
                sql = "select @@IDENTITY from policies"
                cmd.CommandText = sql
                policy.id = cmd.ExecuteScalar
                cmd.CommandText = "set IDENTITY_INSERT policies OFF"
                cmd.ExecuteNonQuery()
            Else
                sql = "insert into policies(name, checkin_time, reboot_reminder_1, reboot_reminder_2, reboot_reminder_3, reboot_reminder_interval, reboot_reminder_schedule, reboot_reminder_scheduled_day, au_enabled, au_day, au_time) "
                sql = sql & " values("
                sql = sql & "'policy_" & r.Next(1, 7052007) & "', " & policy.checkInTime & ", '" & policy.rebootPolicy.time1 & "', '" & policy.rebootPolicy.time2 & "', '" & policy.rebootPolicy.time3 & "', " & policy.rebootPolicy.everyFewMinutes & ", " & policy.rebootPolicy.rebootSchedule & ", " & policy.rebootPolicy.scheduledRebootDay & ", " & translatePolicy & ", " & policy.auPolicy.day & ", '" & policy.auPolicy.time & "'"
                sql = sql & ")"
                sqlData.Close()
                cmd.CommandText = sql
                cmd.ExecuteNonQuery()
                sql = "select @@IDENTITY from policies"
                cmd.CommandText = sql
                policy.id = cmd.ExecuteScalar
            End If
        End If

        disconnect(DB)
    End Sub

    Public Sub applyPolicyToGroup(ByVal policyID As Integer, ByVal groupID As Integer)
        Dim cmd As System.Data.SqlClient.SqlCommand
        Dim sql As String
        Dim DB As System.Data.SqlClient.SqlConnection = connect()

        sql = "update groups set policy_id = " & policyID & " where id = " & groupID
        cmd = New Data.SqlClient.SqlCommand(sql, DB)
        cmd.ExecuteNonQuery()

        disconnect(DB)
    End Sub

    Public Function getComputerGroups(ByVal baseID As Integer) As String
        Dim returner As String = ""
        Dim cmd As System.Data.SqlClient.SqlCommand
        Dim sqlData As System.Data.SqlClient.SqlDataReader
        Dim sql As String
        Dim DB As System.Data.SqlClient.SqlConnection = connect()

        sql = "select * from groups where parent_id = " & baseID
        cmd = New Data.SqlClient.SqlCommand(sql, DB)
        sqlData = cmd.ExecuteReader

        While sqlData.Read()
            If returner = "" Then
                returner = sqlData.Item("id") & ":" & sqlData.Item("name") & ":" & sqlData.Item("description")
            Else
                returner = returner & ControlChars.NullChar & sqlData.Item("id") & ":" & sqlData.Item("name") & ":" & sqlData.Item("description")
            End If
        End While
        sqlData.Close()

        disconnect(DB)
        Return returner
    End Function

    Public Function newComputerGroup(ByVal strings As String) As String
        Dim parent As Integer
        Dim name As String
        Dim desc As String
        Dim returner As String = ""
        Dim cmd As System.Data.SqlClient.SqlCommand
        Dim sql As String
        Dim DB As System.Data.SqlClient.SqlConnection = connect()

        parent = strings.Substring(0, strings.IndexOf(":"))
        name = strings.Substring(strings.IndexOf(":") + 1, (strings.IndexOf(":", strings.IndexOf(":") + 1) - strings.IndexOf(":")) - 1)
        desc = strings.Substring(strings.IndexOf(":", strings.IndexOf(":") + 1) + 1)

        sql = "insert into groups(name, description, parent_id) values('" & name & "', '" & desc & "', '" & parent & "')"
        cmd = New Data.SqlClient.SqlCommand(sql, DB)
        cmd.ExecuteNonQuery()
        cmd.CommandText = "select @@IDENTITY from groups"
        returner = cmd.ExecuteScalar

        disconnect(DB)
        Return returner
    End Function

    Public Function delComputerGroup(ByVal strings As String) As String
        Dim returner As String = ""
        Dim cmd As System.Data.SqlClient.SqlCommand
        Dim sql As String
        Dim DB As System.Data.SqlClient.SqlConnection = connect()

        sql = "delete from groups where id = " & strings.Trim(ControlChars.NullChar)
        cmd = New Data.SqlClient.SqlCommand(sql, DB)
        cmd.ExecuteNonQuery()
        sql = "update clients set group_id = 0 where group_id = " & strings.Trim(ControlChars.NullChar)
        cmd.CommandText = sql
        cmd.ExecuteNonQuery()

        disconnect(DB)
        returner = "0"
        Return returner
    End Function

    Public Function editComputerGroup(ByVal strings As String) As String
        Dim returner As String = ""
        Dim cmd As System.Data.SqlClient.SqlCommand
        Dim sql As String
        Dim groupID As Integer
        Dim name As String
        Dim desc As String
        Dim DB As System.Data.SqlClient.SqlConnection = connect()

        groupID = strings.Substring(0, strings.IndexOf(":"))
        name = strings.Substring(strings.IndexOf(":") + 1, (strings.IndexOf(":", strings.IndexOf(":") + 1) - strings.IndexOf(":")) - 1)
        desc = strings.Substring(strings.IndexOf(":", strings.IndexOf(":") + 1) + 1, strings.IndexOf(ControlChars.NullChar))

        sql = "update groups set name = '" & name & "', description = '" & desc & "' where id = " & groupID
        cmd = New Data.SqlClient.SqlCommand(sql, DB)
        cmd.ExecuteNonQuery()

        disconnect(DB)
        returner = "0"
        Return returner
    End Function

    Public Function listGroupMembers(ByVal strings As String) As String()
        Dim returner() As String
        Dim rowCnt As Integer = -1
        Dim cmd As System.Data.SqlClient.SqlCommand
        Dim sqlData As System.Data.SqlClient.SqlDataReader
        Dim sql As String
        Dim DB As System.Data.SqlClient.SqlConnection = connect()

        sql = "select * from clients where group_id = " & strings
        cmd = New Data.SqlClient.SqlCommand(sql, DB)
        sqlData = cmd.ExecuteReader
        While sqlData.Read
            rowCnt = rowCnt + 1
            ReDim Preserve returner(rowCnt)
            '(0)
            returner(rowCnt) = sqlData.Item("computer_name").ToString
            returner(rowCnt) = returner(rowCnt) & "##" & sqlData.Item("last_ip").ToString
            returner(rowCnt) = returner(rowCnt) & "##" & sqlData.Item("last_checkin").ToString
            returner(rowCnt) = returner(rowCnt) & "##" & sqlData.Item("id").ToString
            returner(rowCnt) = returner(rowCnt) & "##" & sqlData.Item("overall_status").ToString
            returner(rowCnt) = returner(rowCnt) & "##" & sqlData.Item("machine_make").ToString
            returner(rowCnt) = returner(rowCnt) & "##" & sqlData.Item("machine_model").ToString
            returner(rowCnt) = returner(rowCnt) & "##" & sqlData.Item("thermal_state").ToString
            returner(rowCnt) = returner(rowCnt) & "##" & sqlData.Item("system_arch").ToString
            returner(rowCnt) = returner(rowCnt) & "##" & sqlData.Item("cpu_count").ToString
            '(10)
            returner(rowCnt) = returner(rowCnt) & "##" & sqlData.Item("loggedin_user").ToString
            returner(rowCnt) = returner(rowCnt) & "##" & sqlData.Item("serial_number").ToString
            returner(rowCnt) = returner(rowCnt) & "##" & sqlData.Item("os_name").ToString
            returner(rowCnt) = returner(rowCnt) & "##" & sqlData.Item("os_version").ToString
            returner(rowCnt) = returner(rowCnt) & "##" & sqlData.Item("free_ram").ToString
            returner(rowCnt) = returner(rowCnt) & "##" & sqlData.Item("total_ram").ToString
            returner(rowCnt) = returner(rowCnt) & "##" & sqlData.Item("uptime").ToString
            returner(rowCnt) = returner(rowCnt) & "##" & sqlData.Item("local_drive_letters").ToString
            returner(rowCnt) = returner(rowCnt) & "##" & sqlData.Item("local_drive_percent_free").ToString
            returner(rowCnt) = returner(rowCnt) & "##" & sqlData.Item("local_drive_free_space").ToString
            '(20)
            returner(rowCnt) = returner(rowCnt) & "##" & sqlData.Item("cpu_title").ToString
            returner(rowCnt) = returner(rowCnt) & "##" & sqlData.Item("cpu_speed").ToString
            returner(rowCnt) = returner(rowCnt) & "##" & sqlData.Item("process_count").ToString
            returner(rowCnt) = returner(rowCnt) & "##" & sqlData.Item("thread_count").ToString
            returner(rowCnt) = returner(rowCnt) & "##" & sqlData.Item("client_version").ToString
            returner(rowCnt) = returner(rowCnt) & "##" & sqlData.Item("session_status").ToString
        End While
        sqlData.Close()
        disconnect(DB)
        Return returner
    End Function

    Public Function getClientDetails(ByVal clientID As String) As String
        Dim returner As String
        Dim cmd As System.Data.SqlClient.SqlCommand
        Dim sqlData As System.Data.SqlClient.SqlDataReader
        Dim sql As String
        Dim DB As System.Data.SqlClient.SqlConnection = connect()

        sql = "select * from clients where id = '" & clientID & "'"
        cmd = New Data.SqlClient.SqlCommand(sql, DB)
        sqlData = cmd.ExecuteReader
        If sqlData.Read Then
            '(0)
            returner = sqlData.Item("computer_name").ToString
            returner = returner & "##" & sqlData.Item("last_ip").ToString
            returner = returner & "##" & sqlData.Item("last_checkin").ToString
            returner = returner & "##" & sqlData.Item("id").ToString
            returner = returner & "##" & sqlData.Item("overall_status").ToString
            returner = returner & "##" & sqlData.Item("machine_make").ToString
            returner = returner & "##" & sqlData.Item("machine_model").ToString
            returner = returner & "##" & sqlData.Item("thermal_state").ToString
            returner = returner & "##" & sqlData.Item("system_arch").ToString
            returner = returner & "##" & sqlData.Item("cpu_count").ToString
            '(10)
            returner = returner & "##" & sqlData.Item("loggedin_user").ToString
            returner = returner & "##" & sqlData.Item("serial_number").ToString
            returner = returner & "##" & sqlData.Item("os_name").ToString
            returner = returner & "##" & sqlData.Item("os_version").ToString
            returner = returner & "##" & sqlData.Item("free_ram").ToString
            returner = returner & "##" & sqlData.Item("total_ram").ToString
            returner = returner & "##" & sqlData.Item("uptime").ToString
            returner = returner & "##" & sqlData.Item("local_drive_letters").ToString
            returner = returner & "##" & sqlData.Item("local_drive_percent_free").ToString
            returner = returner & "##" & sqlData.Item("local_drive_free_space").ToString
            '(20)
            returner = returner & "##" & sqlData.Item("cpu_title").ToString
            returner = returner & "##" & sqlData.Item("cpu_speed").ToString
            returner = returner & "##" & sqlData.Item("process_count").ToString
            returner = returner & "##" & sqlData.Item("thread_count").ToString
            returner = returner & "##" & sqlData.Item("client_version").ToString
            returner = returner & "##" & sqlData.Item("session_status").ToString
        End If
        sqlData.Close()
        disconnect(DB)
        Return returner
    End Function

    Public Function changeComputerGroup(ByVal strings As String) As String
        Dim returner As String = ""
        Dim ids() As String
        Dim cmd As System.Data.SqlClient.SqlCommand
        Dim sql As String
        Dim DB As System.Data.SqlClient.SqlConnection = connect()

        ids = Split(strings, ":")
        sql = "update clients set group_id = " & ids(1) & " where id in ('00000000-0000-0000-0000-000000000000', " & ids(0) & ")"
        cmd = New Data.SqlClient.SqlCommand(sql, DB)
        cmd.ExecuteNonQuery()

        returner = "OK"
        disconnect(DB)
        Return returner
    End Function

    Public Function scheduleClientAction(ByVal action As protocolType, ByVal allClients() As String, ByVal allDetails() As String) As String
        Dim returner As String = ""
        Dim cmd As New System.Data.SqlClient.SqlCommand
        Dim sql As String
        Dim i As Integer
        Dim DB As System.Data.SqlClient.SqlConnection = connect()

        cmd.Connection = DB
        If action = protocolType.A_renameComputers Then
            For i = 0 To allClients.Length - 1
                sql = "insert into clients_to_do(client_id, client_action, details, date_added) values("
                sql = sql & "'" & allClients(i) & "', '" & action & "', '" & allDetails(i) & "', getdate())"
                cmd.CommandText = sql
                cmd.ExecuteNonQuery()
            Next
        End If

        returner = "OK"
        disconnect(DB)
        Return returner
    End Function

    Public Sub setClientRebootFlag(ByVal clientGUID As String)
        Dim cmd As New Data.SqlClient.SqlCommand
        Dim DB As System.Data.SqlClient.SqlConnection = connect()

        cmd.Connection = DB
        cmd.CommandText = "update clients set reboot_flag = " & Now.ToBinary & " where id = '" & clientGUID & "'"
        cmd.ExecuteNonQuery()
        disconnect(DB)
    End Sub

    Public Sub clearClientRebootFlag(ByVal clientGUID As String)
        Dim cmd As New Data.SqlClient.SqlCommand
        Dim DB As System.Data.SqlClient.SqlConnection = connect()

        cmd.Connection = DB
        cmd.CommandText = "update clients set reboot_flag = '' where id = '" & clientGUID & "'"
        cmd.ExecuteNonQuery()
        disconnect(DB)
    End Sub

    Public Function handleScheduledActions(ByRef client As ERN_Server.ernClients, ByRef net As ernNetwork.server) As String
        Dim returner As String = ""
        Dim cmd As New System.Data.SqlClient.SqlCommand
        Dim data As Data.SqlClient.SqlDataReader
        Dim renameList() As String = Nothing
        Dim completedIDs() As String = Nothing
        Dim item As String
        Dim itemCount As Integer = 0
        Dim sql As String
        Dim DB As System.Data.SqlClient.SqlConnection = connect()

        cmd.Connection = DB
        sql = "select * from clients_to_do where client_id = '" & client.guid & "' ORDER BY date_added ASC"
        cmd.CommandText = sql
        data = cmd.ExecuteReader

        If data.HasRows Then
            While data.Read
                If CType(data.Item("client_action"), protocolType) = protocolType.A_renameComputers Then
                    'rename computer!!!!
                    'send rename computer message to client
                    If net.renameClient(data.Item("details").ToString) Then
                        returner = "OK"

                        ReDim Preserve completedIDs(itemCount)
                        ReDim Preserve renameList(itemCount)
                        completedIDs(itemCount) = data.Item("id").ToString
                        renameList(itemCount) = data.Item("client_id").ToString & ":" & data.Item("details").ToString
                        itemCount = itemCount + 1
                    Else
                        returner = "ERROR"
                    End If

                    ' ID in client_to_do to delete data.Item("id").ToString
                    ' ID in clients to rename data.item("client_id")

                    'if rename was good then
                    'delete the row from client_to_do
                    'rename computer
                End If
            End While

            data.Close()

            If itemCount > 0 Then
                markClientToReboot(client, net)
                For Each item In completedIDs
                    cmd.CommandText = "delete from clients_to_do where id = " & item
                    cmd.ExecuteNonQuery()
                Next

                For Each item In renameList
                    cmd.CommandText = "update clients set computer_name = '" & Split(item, ":")(1) & "' where id = '" & Split(item, ":")(0) & "'"
                    cmd.ExecuteNonQuery()
                Next
            End If
        Else
            data.Close()
            returner = "OK"
        End If

        'MsgBox(returner)

        Return returner
        disconnect(DB)
    End Function

    Public Function newAutoUpdatePatch(ByVal info As String) As Integer
        Dim cmd As New Data.SqlClient.SqlCommand
        Dim DB As System.Data.SqlClient.SqlConnection = connect()
        Dim strings() As String
        Dim returner As Integer
        Dim temp As String = ""
        Dim temps() As String
        Dim tempV As String = ""
        Dim tempVs() As String

        strings = Split(info, "::")
        cmd.Connection = DB
        temps = Split(strings(6), ".")
        For returner = 0 To temps.Length - 1
            If temps(returner).Length < 2 Then temps(returner) = "0" & temps(returner)
            'when returner is 0 we dont do anything, when it is 1 we put a decimal point
            'and after then we just join it all together so 1.1.1.1 becomes 01.010101
            If returner = 1 Then
                temp = temp & "." & temps(returner)
            Else
                temp = temp & temps(returner)
            End If
        Next
        'then we add a 1 at the end as a place holder so if the number was 1.0.1.0
        'we'd get 01.0001001 and when saved as a decimal 1.0001001
        'instead of 01.000100 and when saved as a decimal 1.0001 which the original version
        'is unrecoverable.
        temp = temp & "1"

        tempVs = Split(strings(2), ".")
        For returner = 0 To tempVs.Length - 1
            If tempVs(returner).Length < 2 Then tempVs(returner) = "0" & tempVs(returner)
            'when returner is 0 we dont do anything, when it is 1 we put a decimal point
            'and after then we just join it all together so 1.1.1.1 becomes 01.010101
            If returner = 1 Then
                tempV = tempV & "." & tempVs(returner)
            Else
                tempV = tempV & tempVs(returner)
            End If
        Next
        'then we add a 1 at the end as a place holder so if the number was 1.0.1.0
        'we'd get 01.0001001 and when saved as a decimal 1.0001001
        'instead of 01.000100 and when saved as a decimal 1.0001 which the original version
        'is unrecoverable.
        tempV = tempV & "1"

        If strings(5) = "*" Then strings(5) = "null" Else strings(5) = "'" & Date.Parse(strings(5)) & "'"
        cmd.CommandText = "insert into autoupdate_patches(created_datetime, published_datetime, version, published_by, uploaded_name, server_filename, file_size, md5_hash, required_version) values(getdate(), " & strings(5) & ", '" & tempV & "', '" & strings(1) & "', '" & strings(0) & "', '', '" & strings(3) & "', '" & strings(4) & "', " & temp & ")"
        cmd.ExecuteNonQuery()

        cmd.CommandText = "select @@IDENTITY from autoupdate_patches"
        returner = cmd.ExecuteScalar
        disconnect(DB)

        Return returner
    End Function

    Public Sub updateAutoUpdatePatchFilename(ByVal id As Integer, ByVal filename As String)
        Dim cmd As New Data.SqlClient.SqlCommand
        Dim DB As System.Data.SqlClient.SqlConnection = connect()

        cmd.Connection = DB
        cmd.CommandText = "update autoupdate_patches set server_filename = '" & filename & "' where id = " & id
        cmd.ExecuteNonQuery()
        disconnect(DB)
    End Sub

    Public Sub updateAutoUpdatePatchInfo(ByVal id As Integer, ByVal publishDate As String, ByVal version As String, Optional ByVal requiredVersion As String = "")
        Dim cmd As New Data.SqlClient.SqlCommand
        Dim DB As System.Data.SqlClient.SqlConnection = connect()
        Dim temp As String = ""
        Dim temps() As String
        Dim tempV As String = ""
        Dim tempVs() As String
        Dim i As Integer

        cmd.Connection = DB
        If publishDate = "*" Then publishDate = "null" Else publishDate = "'" & Date.Parse(publishDate) & "'"
        If version = "" Then
            cmd.CommandText = "update autoupdate_patches set published_datetime = " & publishDate & " where id = " & id
        ElseIf publishDate = "" Then
            temps = Split(requiredVersion, ".")
            For i = 0 To temps.Length - 1
                If temps(i).Length < 2 Then temps(i) = "0" & temps(i)
                'when returner is 0 we dont do anything, when it is 1 we put a decimal point
                'and after then we just join it all together so 1.1.1.1 becomes 01.010101
                If i = 1 Then
                    temp = temp & "." & temps(i)
                Else
                    temp = temp & temps(i)
                End If
            Next
            'then we add a 1 at the end as a place holder so if the number was 1.0.1.0
            'we'd get 01.0001001 and when saved as a decimal 1.0001001
            'instead of 01.000100 and when saved as a decimal 1.0001 which the original version
            'is unrecoverable.
            temp = temp & "1"
            tempVs = Split(version, ".")
            For i = 0 To tempVs.Length - 1
                If tempVs(i).Length < 2 Then tempVs(i) = "0" & tempVs(i)
                'when returner is 0 we dont do anything, when it is 1 we put a decimal point
                'and after then we just join it all together so 1.1.1.1 becomes 01.010101
                If i = 1 Then
                    tempV = tempV & "." & tempVs(i)
                Else
                    tempV = tempV & tempVs(i)
                End If
            Next
            'then we add a 1 at the end as a place holder so if the number was 1.0.1.0
            'we'd get 01.0001001 and when saved as a decimal 1.0001001
            'instead of 01.000100 and when saved as a decimal 1.0001 which the original version
            'is unrecoverable.
            tempV = tempV & "1"
            cmd.CommandText = "update autoupdate_patches set version = '" & tempV & "', required_version = '" & temp & "' where id = " & id
        Else
            temps = Split(requiredVersion, ".")
            For i = 0 To temps.Length - 1
                If temps(i).Length < 2 Then temps(i) = "0" & temps(i)
                'when returner is 0 we dont do anything, when it is 1 we put a decimal point
                'and after then we just join it all together so 1.1.1.1 becomes 01.010101
                If i = 1 Then
                    temp = temp & "." & temps(i)
                Else
                    temp = temp & temps(i)
                End If
            Next
            'then we add a 1 at the end as a place holder so if the number was 1.0.1.0
            'we'd get 01.0001001 and when saved as a decimal 1.0001001
            'instead of 01.000100 and when saved as a decimal 1.0001 which the original version
            'is unrecoverable.
            temp = temp & "1"
            tempVs = Split(version, ".")
            For i = 0 To tempVs.Length - 1
                If tempVs(i).Length < 2 Then tempVs(i) = "0" & tempVs(i)
                'when returner is 0 we dont do anything, when it is 1 we put a decimal point
                'and after then we just join it all together so 1.1.1.1 becomes 01.010101
                If i = 1 Then
                    tempV = tempV & "." & tempVs(i)
                Else
                    tempV = tempV & tempVs(i)
                End If
            Next
            'then we add a 1 at the end as a place holder so if the number was 1.0.1.0
            'we'd get 01.0001001 and when saved as a decimal 1.0001001
            'instead of 01.000100 and when saved as a decimal 1.0001 which the original version
            'is unrecoverable.
            tempV = tempV & "1"
            cmd.CommandText = "update autoupdate_patches set published_datetime = " & publishDate & ", version = '" & tempV & "', required_version = '" & temp & "' where id = " & id
        End If
        cmd.ExecuteNonQuery()
        disconnect(DB)
    End Sub

    Public Function getAutoUpdateList() As String()
        Dim cmd As New Data.SqlClient.SqlCommand
        Dim cmd2 As New Data.SqlClient.SqlCommand
        Dim DB As System.Data.SqlClient.SqlConnection = connect()
        Dim DB2 As System.Data.SqlClient.SqlConnection
        Dim data As Data.SqlClient.SqlDataReader
        Dim returner(0) As String
        Dim requiredVersion As String
        Dim Version As String
        Dim minorVersions As String
        Dim i As Integer

        cmd.Connection = DB
        cmd.CommandText = "select *  from autoupdate_patches order by published_datetime"
        Data = cmd.ExecuteReader

        If data.HasRows Then
            While data.Read
                If returner(returner.Length - 1) <> Nothing Then
                    ReDim Preserve returner(returner.Length)
                End If
                requiredVersion = Split(data.Item("required_version").ToString.Trim(CChar(CStr("0"))), ".")(0)
                minorVersions = Split(data.Item("required_version").ToString.Trim(CChar(CStr("0"))), ".")(1)
                minorVersions = minorVersions.Substring(0, minorVersions.Length - 1)
                If requiredVersion = "" Then requiredVersion = "0"
                If requiredVersion < 10 Then requiredVersion = "0" & requiredVersion

                For i = 0 To ((minorVersions.Length / 2) - 1)
                    requiredVersion = requiredVersion & "." & minorVersions.Substring(i * 2, 2)
                Next

                Version = Split(data.Item("version").ToString.Trim(CChar(CStr("0"))), ".")(0)
                minorVersions = Split(data.Item("version").ToString.Trim(CChar(CStr("0"))), ".")(1)
                minorVersions = minorVersions.Substring(0, minorVersions.Length - 1)
                If Version = "" Then Version = "0"
                If Version < 10 Then Version = "0" & Version

                For i = 0 To ((minorVersions.Length / 2) - 1)
                    Version = Version & "." & minorVersions.Substring(i * 2, 2)
                Next

                returner(returner.Length - 1) = Version
                returner(returner.Length - 1) = returner(returner.Length - 1) & "::" & requiredVersion
                returner(returner.Length - 1) = returner(returner.Length - 1) & "::" & data.Item("created_datetime")
                returner(returner.Length - 1) = returner(returner.Length - 1) & "::" & data.Item("published_datetime")
                returner(returner.Length - 1) = returner(returner.Length - 1) & "::" & data.Item("published_by")
                returner(returner.Length - 1) = returner(returner.Length - 1) & "::" & data.Item("uploaded_name")
                'install count...
                DB2 = connect()
                cmd2.Connection = DB2
                cmd2.CommandText = "select count(*) from autoupdate_installs where autoupdate_id = " & data.Item("id")
                returner(returner.Length - 1) = returner(returner.Length - 1) & "::" & cmd2.ExecuteScalar()
                returner(returner.Length - 1) = returner(returner.Length - 1) & "::" & data.Item("id")
                disconnect(DB2)
            End While
        End If
        disconnect(DB)

        Return returner
    End Function

    Public Function getAUInstallList(ByVal au_id As String) As String()
        Dim cmd As New Data.SqlClient.SqlCommand
        Dim DB As System.Data.SqlClient.SqlConnection = connect()
        Dim data As Data.SqlClient.SqlDataReader
        Dim returner(0) As String

        cmd.Connection = DB
        cmd.CommandText = "select i.*, c.computer_name from autoupdate_installs as i, clients as c where c.id = i.client_id and i.autoupdate_id = " & au_id
        data = cmd.ExecuteReader

        If data.HasRows Then
            While data.Read
                If returner(returner.Length - 1) <> Nothing Then
                    ReDim Preserve returner(returner.Length + 1)
                End If
                returner(returner.Length - 1) = data.Item("computer_name")
                returner(returner.Length - 1) = returner(returner.Length - 1) & "::" & data.Item("installed_datetime")
                returner(returner.Length - 1) = returner(returner.Length - 1) & "::" & data.Item("return_value")
            End While
        End If
        disconnect(DB)

        Return returner
    End Function

    Public Sub deleteAUItem(ByVal updateID As Integer)
        Dim cmd As New Data.SqlClient.SqlCommand
        Dim DB As System.Data.SqlClient.SqlConnection = connect()

        cmd.Connection = DB
        cmd.CommandText = "delete from autoupdate_installs where autoupdate_id = " & updateID
        cmd.ExecuteNonQuery()
        cmd.CommandText = "delete from autoupdate_patches where id = " & updateID
        cmd.ExecuteNonQuery()

        disconnect(DB)
    End Sub

    Public Sub setAUPublishDefaults(ByVal enabled As String, ByVal day As String, ByVal hour As String, ByVal minute As String, ByVal ampm As String)
        Dim cmd As New Data.SqlClient.SqlCommand
        Dim DB As System.Data.SqlClient.SqlConnection = connect()

        cmd.Connection = DB
        cmd.CommandText = "select count(*) from config where config_key = 'au_publishEnabled'"
        If cmd.ExecuteScalar = 0 Then
            'do inserts instead of updates
            cmd.Connection = DB
            cmd.CommandText = "insert into config(config_key, config_value) values('au_publishEnabled', '" & enabled & "')"
            cmd.ExecuteNonQuery()
            cmd.Connection = DB
            cmd.CommandText = "insert into config(config_key, config_value) values('au_publishDay', '" & day & "')"
            cmd.ExecuteNonQuery()
            cmd.Connection = DB
            cmd.CommandText = "insert into config(config_key, config_value) values('au_publishTime', '" & hour & ":" & minute & ":" & ampm & "')"
            cmd.ExecuteNonQuery()
        Else
            'do updates instead of inserts
            cmd.Connection = DB
            cmd.CommandText = "update config set config_value = '" & enabled & "' where config_key = 'au_publishEnabled'"
            cmd.ExecuteNonQuery()
            cmd.Connection = DB
            cmd.CommandText = "update config set config_value = '" & day & "' where config_key = 'au_publishDay'"
            cmd.ExecuteNonQuery()
            cmd.Connection = DB
            cmd.CommandText = "update config set config_value = '" & hour & ":" & minute & ":" & ampm & "' where config_key = 'au_publishTime'"
            cmd.ExecuteNonQuery()
        End If

        disconnect(DB)
    End Sub

    Public Function getAUPublishDefaults() As String()
        Dim returner(2) As String
        Dim cmd As New Data.SqlClient.SqlCommand
        Dim DB As System.Data.SqlClient.SqlConnection = connect()

        cmd.Connection = DB
        cmd.CommandText = "select config_value from config where config_key = 'au_publishEnabled'"
        returner(0) = cmd.ExecuteScalar
        cmd.CommandText = "select config_value from config where config_key = 'au_publishDay'"
        returner(1) = cmd.ExecuteScalar
        cmd.CommandText = "select config_value from config where config_key = 'au_publishTime'"
        returner(2) = cmd.ExecuteScalar
        disconnect(DB)

        Return returner
    End Function

    Public Function checkForAU(ByRef c As ERN_Server.ernClients) As String()
        Dim cmd As New Data.SqlClient.SqlCommand
        Dim DB As System.Data.SqlClient.SqlConnection = connect()
        Dim data As Data.SqlClient.SqlDataReader
        Dim returner() As String = Nothing
        Dim foundUpdate As Boolean = False
        Dim temp As String = ""
        Dim temps() As String
        Dim i As Integer

        If c.policy.auPolicy.enabled Then
            ReDim returner(6)

            temps = Split(c.clientVersion, ".")
            For i = 0 To temps.Length - 1
                If temps(i).Length < 2 Then temps(i) = "0" & temps(i)
                'when returner is 0 we dont do anything, when it is 1 we put a decimal point
                'and after then we just join it all together so 1.1.1.1 becomes 01.010101
                If i = 1 Then
                    temp = temp & "." & temps(i)
                Else
                    temp = temp & temps(i)
                End If
            Next
            'then we add a 1 at the end as a place holder so if the number was 1.0.1.0
            'we'd get 01.0001001 and when saved as a decimal 1.0001001
            'instead of 01.000100 and when saved as a decimal 1.0001 which the original version
            'is unrecoverable.
            temp = temp & "1"

            cmd.Connection = DB
            cmd.CommandText = "select * from autoupdate_patches as a where required_version <= " & temp & " and version > " & temp & " and published_datetime <= getdate() ORDER BY version DESC"
            data = cmd.ExecuteReader

            If data.HasRows Then
                While Not foundUpdate
                    data.Read()

                    If Date.Today.Subtract(Date.Parse(data("published_datetime"))).Days <= 6 Then
                        If Date.Parse(data("published_datetime")).DayOfWeek <= Date.Today.DayOfWeek Then
                            foundUpdate = True
                        End If
                    Else
                        foundUpdate = True
                    End If
                End While
                If foundUpdate Then
                    returner(0) = data("id")
                    returner(1) = data("published_datetime")
                    returner(2) = data("version")
                    returner(3) = data("server_filename")
                    returner(4) = data("uploaded_name")
                    returner(5) = data("md5_hash")
                    returner(6) = data("file_size")
                End If
            End If


        End If

        disconnect(DB)
        Return returner
    End Function

    Public Sub clientUpdateInstalled(ByVal auID As Integer, ByVal clientID As String, ByVal installedTime As String, ByVal returnValue As Integer, ByVal returnText As String)
        Dim cmd As New Data.SqlClient.SqlCommand
        Dim DB As System.Data.SqlClient.SqlConnection = connect()
        
        cmd.Connection = DB
        cmd.CommandText = "insert into autoupdate_installs(autoupdate_id, client_id, installed_datetime, return_value, return_text) values('" & auID & "', '" & clientID & "', '" & installedTime & "', '" & returnValue & "', '" & returnText & "')"
        cmd.ExecuteNonQuery()
        
        disconnect(DB)
    End Sub
End Class
